package com.ffx.web.servlet;

import com.alibaba.fastjson.JSON;
import com.ffx.service.ClassesService;
import com.ffx.service.impl.ClassesServiceImpl;
import org.junit.internal.Classes;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @outhor fufeixiang
 * @date 2021-11-08
 */
@WebServlet("/classes")
public class ClassesServlet extends HttpServlet {
    private ClassesService classessService;

    @Override
    public void init() throws ServletException {
        classessService = new ClassesServiceImpl();
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf8");
        //1. 查询所有所有班级
        List<Classes> classes = classessService.findAll();
        //2. 转换为json串并输出
        resp.getWriter().println(JSON.toJSONString(classes));
        resp.getWriter().flush();
    }

}
